package dao

import (
	"2y7zk/inits"
	"2y7zk/models"
)

func CreateMessage(formUserId int, ToUserId int, message string) bool {

	var min1 = formUserId
	var max1 = ToUserId

	if formUserId > ToUserId {
		min1 = ToUserId
		max1 = formUserId
	}

	m := models.Message{
		FormUserId: formUserId,
		ToUserId:   ToUserId,
		RoomId:     min1*100000 + max1,
		Message:    message,
	}
	if inits.DB.Debug().Create(&m) != nil {
		return false
	}
	return false

}

func CreateFriend(result models.Friend) error {
	return inits.DB.Debug().Create(&result).Error

}
func List() (list []models.Message, err error) {
	inits.DB.Debug().Find(&list)
	return
}

func Del(FriendId int) error {
	return inits.DB.Debug().Delete("friend_id", FriendId).Error
}
